`
https://leetcode.cn/problems/find-elements-in-a-contaminated-binary-tree/
`

/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 */
var FindElements = function (root) {
  // find 函数里只需要寻找存不存在，所以使用集合记录树里面所有出现过的值即可
  const values = new Set()
  values.add(0)

  root.val = 0

  const traverse = (root) => {
    if (root === null) return

    if (root.left) {
      root.left.val = 2 * root.val + 1
      values.add(root.left.val)
      traverse(root.left)
    }
    if (root.right) {
      root.right.val = 2 * root.val + 2
      values.add(root.right.val)
      traverse(root.right)
    }
  }

  traverse(root)

  this.values = values
};

/** 
* @param {number} target
* @return {boolean}
*/
FindElements.prototype.find = function (target) {
  return this.values.has(target)
};

/** 
* Your FindElements object will be instantiated and called as such:
* var obj = new FindElements(root)
* var param_1 = obj.find(target)
*/